<?php
	$registry   = Zend_Registry::getInstance();
	$constants = $registry->constants;
	$this->headLink()->appendStylesheet($this->baseUrl().'/static/css/main.css');
	$this->headScript()->appendFile("/static/js/jquery.js");
	$this->headScript()->appendFile("/static/js/jquery-ui-1.10.3.custom.js");
	$this->headScript()->appendFile("/static/js/jquery-ui-1.10.3.custom.min.js");
	
?>
<html>
	<head>
		<meta charset="utf-8">
		<title>Login</title>
		<?php 
			echo $this->headLink();
			echo $this->headScript();
			?>
		<link rel="shortcut icon" href="/static/images/favicon.png">
	</head>
	<body>
		<div class="wrapper">
			
			<div class="header">
				<div class="topbar-center">
					<span style="color:#DF5A49;font-weight: bold">LOGIN</span>
				</div>
			</div>
			
			<div class="content">
				<div class="login-content">
					<form id="login_form" action="index/login2">
						<div class="login-alert" id="alert"></div>
						<div class="login-left">User Name(*)</div>
							<input class="login-input" maxlength="45" type="text" id="user_name" name="userName" placeholder="User Name" />
						<div class="login-left">Password(*)</div>
							<input id="password" maxlength="45" class="login-input" type="password" name="password" placeholder="Password"/>
					</form>
					<button class="button-test" id="login" onclick="checkLogin()">Login</button>	
				</div>
				
			</div>
			
			
			<div class="footer">
				<span class="footer-title"> <i>GIGATUM</i></span>
			</div>
			
			
		</div>

	</body>
</html>
<script type="text/javascript">
	$(document).ready(function() {
  		$("#user_name").focus();
  		$("#login_form").keyup(function(event){
  			if(event.keyCode == 13){
  				$("#login").click();
  			}
  		});
	});
	
	function checkLogin(){
		user_name = $.trim($("#user_name").val());
		password = $.trim($("#password").val());
		
		if(user_name != '' && password != ''){
			var form = new FormData($('#login_form')[0]);
			$.ajax({
					url : '/place/index/login/',
					type : 'POST',
					data : form,
					success : function(res) {
						if(res == '<?php echo $constants->SUCCESS_STRING; ?>'){
							window.location.href = '/place/index/logined';
						}else{
							$("#alert").text(res);
							$("#user_name").focus();
							$("#user_name").select();
						}
					},
					cache : false,
					contentType : false,
					processData : false
				});
		}else{
			$("#user_name").focus();
			$("#user_name").select();
			$("#alert").text("<?php echo $constants->MISSING_PARAMETER; ?>");
		}
		
	}
</script>
